package com.wan.thread.async;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;

public class AsyncNextTask<P,R> implements Callable<R> {
    public static final long TIME_OUT = 8000L;

    private final Future<P> future;
    private final Function<P,R> doing;

    public AsyncNextTask(Future<P> future, Function<P, R> doing) {
        this.future = future;
        this.doing = doing;
    }


    @Override
    public R call() throws Exception {
        return doing.apply(future.get(TIME_OUT, TimeUnit.MILLISECONDS));
    }
}
